package com.wb.web.controller.exams;


import com.wb.common.core.controller.BaseController;
import com.wb.common.core.domain.AjaxResult;
import com.wb.common.core.page.TableDataInfo;
import com.wb.common.vo.DeleteRequest;
import com.wb.common.vo.ExamsLevelModelVO;
import com.wb.common.vo.ExamsLevelModelVO;
import com.wb.common.vo.ExamsLevelReqVO;
import com.wb.system.domain.ExamsLevelEntity;
import com.wb.system.service.ExamsLevelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("examslevel")
@Api(tags = "考试等级/领域表表")
public class ExamsLevelController extends BaseController {
    @Autowired
    private ExamsLevelService examsLevelService;

    @PostMapping("/list")
    @ApiOperation("考试等级/领域表列表")
    public TableDataInfo list(@RequestBody ExamsLevelModelVO examsLevelModelVO) {
        startPage();
        List<ExamsLevelEntity> list = examsLevelService.selectExamsLevelList(examsLevelModelVO);
        return getDataTable(list);
    }

    @PostMapping("/listByExamTypeId")
    @ApiOperation("根据大类考试等级/领域表列表")
    public AjaxResult listByExamTypeId(@RequestBody ExamsLevelReqVO vo) {
        return AjaxResult.success(examsLevelService.listByExamTypeId(vo));
    }

    @GetMapping("/{id}")
    @ApiOperation("获取考试等级/领域表详情")
    public AjaxResult get(@PathVariable("id") Long id) {
        return AjaxResult.success(examsLevelService.selectById(id));
    }

    @PostMapping("/add")
    @ApiOperation("考试等级/领域表创建")
    public AjaxResult add(@Valid @RequestBody ExamsLevelEntity ExamsLevelModelVO) {
        ExamsLevelEntity ExamsLevelEntity = new ExamsLevelEntity();
        BeanUtils.copyProperties(ExamsLevelModelVO, ExamsLevelEntity);
        examsLevelService.saveExamsLevel(ExamsLevelEntity);
        return AjaxResult.success();
    }


    @PostMapping("/update")
    @ApiOperation("更新考试等级/领域表")
    public AjaxResult update(@RequestBody ExamsLevelEntity ExamsLevelModelVO) {
        ExamsLevelEntity ExamsLevelEntity = new ExamsLevelEntity();
        BeanUtils.copyProperties(ExamsLevelModelVO, ExamsLevelEntity);
        //  ExamsLevelEntity.setUpdateBy(getUsername());
        examsLevelService.updateExamsLevelById(ExamsLevelEntity);
        return AjaxResult.success();
    }

    @DeleteMapping("/deleteAll")
    @ApiOperation("删除All")
    public AjaxResult deleteAll(@RequestBody DeleteRequest request) {
        examsLevelService.removeExamsLevelByIds(request.getIds());
        return AjaxResult.success();
    }
}
